﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Admin_Admin_CapNhatTaiKhoanDang2 : System.Web.UI.Page
{
 
    protected void Page_Load(object sender, EventArgs e)
    {
        btnXoa.Attributes["onclick"] = "return confirm('Chắc chắn xóa các tài khoản được chọn?');";

        DataDSTableAdapters.TAIKHOANTableAdapter spadapter = new DataDSTableAdapters.TAIKHOANTableAdapter();
        int currentPage = 0;
        if (Request["page"] != null)
            currentPage = int.Parse(Request["page"]);
        

        int tongDong = int.Parse(spadapter.TAIKHOAN_TongSoDong().ToString());
        
        int rowPerPage = int.Parse(ConfigurationSettings.AppSettings["RowPerPage"]);
        int startIndex = (rowPerPage * currentPage);
        int numOfPage = tongDong / rowPerPage;
        if (tongDong % rowPerPage != 0)
            numOfPage++;

        PageInterface1.currentPageName = GlobalFunctions.GetCurrentPageName();
        PageInterface1.currentPageNumber = currentPage;
        PageInterface1.totalNumberOfPage = numOfPage;

        
        if(!IsPostBack)
        {
            DataList_DSTK.DataSource = spadapter.TAIKHOAN_LayTatCa_Paged(startIndex, rowPerPage);
            DataList_DSTK.DataBind();
        }
        

        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_ThemTaiKhoan.aspx");
    }
    protected void btnXoa_Click(object sender, EventArgs e)
    {
        DataDSTableAdapters.TAIKHOANTableAdapter tkAdapter = new DataDSTableAdapters.TAIKHOANTableAdapter();
        int? kq = 0;
        int count = 0;
        for (int i = 0; i< DataList_DSTK.Items.Count; i++)
        {
            CheckBox ck = (CheckBox)DataList_DSTK.Items[i].FindControl("ckXoa");
            if(ck.Checked)
            {
                string cmnd = ((HyperLink)(DataList_DSTK.Items[i].FindControl("hyperlink_CMND"))).Text;
                tkAdapter.TAIKHOAN_XoaTheoCMND(cmnd, ref kq);
                count++;
                if (kq != 0)
                    Response.Write("<script>alert('Lỗi xóa dữ liệu!')</script>");
            }
            
        }
        if (count == 0)
        {
            Response.Write("<script>alert('Không có dòng nào được chọn!')</script>");
            return;
        }
        Response.Write("<script>alert('Xóa thành công!'); window.location.href='/SMO/ChucNang/Admin/Admin_XemDanhSachTaiKhoan.aspx'</script>");
    }
}
